import { Quote } from '../domain/index';
import { QuoteActions, QuoteActionTypes } from '../actions/quote.action';

export interface State {
    quote: Quote;
}

const initialState: State = {
    quote: {
        cn: '满足感在于不断的努力,而不是现有成就，全新努力定会胜利满满',
        en: 'Satisfaction lies in the effort,not in the attainment, full effort is full ...',
        pic: 'assets/quote_fallback.jpg'
    }
};

export function reducer(state = initialState, action: QuoteActions): State {
    switch (action.type) {
        case QuoteActionTypes.LOAD_SUCCESS: {
            return { ...state, quote: <Quote>action.payload };
        }
        case QuoteActionTypes.LOAD_FAIL:
        default: {
            return state;
        }
    }
}

export const getQuote = (state: State) => state.quote;
